if(Best == undefined){
	var Best = {};
}
Best.FreightSelectPopup = Ext.extend(Ext.Window, {
	width       : 775,
    height      : 286,
	url 		: '',
	callback 	: null,
	isShowAvailableAmount		: true,
	buttonAlign : 'center', 
	initComponent : function(){
        Best.FreightSelectPopup.superclass.initComponent.call(this);
        this.grid = null;
        this.initGrid();
        this.initButtons();
        this.show();
	},
	initGrid: function(){
		var cmArray = [
						{
				           header: '货物编码',
				           dataIndex: 'code',
				           width: 100
				        },{
				           header: '货物名称',
				           dataIndex: 'name',
				           width: 130
				        },{
				           header: '备注',
				           dataIndex: 'description',
				           width: 210
				        },{
				           header: '可用数量',
				           dataIndex: 'availableAmount'
				        },{
				           header: '库存数量',
				           dataIndex: 'balanceAmount'
				        }];
		if(!this.isShowAvailableAmount){
			cmArray.splice(3, 2);
		}
		var cm = new Ext.grid.ColumnModel(cmArray);
	
	    cm.defaultSortable = true;
	

		Ext.extend(Ext.data.JsonStore, Ext.data.Store);
	    // create the Data Store
	    var store = new Ext.data.JsonStore({
	        url: this.url,
	        fields: ['id', 'code', 'name', 'value', 'description', 'balanceAmount', 'availableAmount', 'weight'],
	        root: 'freights',
	        totalProperty: 'fullListSize'
	    });
	    var pageSize = 8;
	    var pagingBar = new Ext.PagingToolbar({
	        pageSize: pageSize,
	        store: store,
	        displayInfo: true,
	        displayMsg: '显示 {0} - {1}条 总数 {2}条',
	        emptyMsg: "没有地址可以显示"
	    });
	    
	    // create the editor grid
	    var width = 760;
	    if(!this.isShowAvailableAmount){
	    	width -= 300;
	    	this.width -= 300;
	    }
	    this.grid = new Ext.grid.GridPanel({
	        store: store,
	        cm: cm,
	        width:width,
	        title:'',
	        frame:true,
	        height: 233,
	        bbar:pagingBar,
	        loadMask:true
	    });
	    this.add(this.grid);
	    this.grid.on('rowdblclick', this.rowdblclick.bind(this));
	    store.load({params:{start:0, limit:pageSize}});
	},
	initButtons: function(){
		var ok = new Ext.Button({
							text: '确定',		
							handler: function(event){
								var records = this.grid.getSelectionModel().getSelections();
								for(var i=0; i<records.length; i++){
									records[i].set('amount', 1);
								}
								
								this.callback(records);
								this.close();
							}.bind(this)	
						});
		var cancel = new Ext.Button({
							text: '取消',		
							handler: function(event){
								this.close();
							}.bind(this)	
						});			
		this.addButton(ok);
		this.addButton(cancel);			
	},
	getBottomBarConfig: function(){
		var result = [{
							text: '确定',
							handler: function(event){
								var records = this.grid.getSelectionModel().getSelections();
								for(var i=0; i<records.length; i++){
									records[i].set('amount', 1);
								}
								
								this.callback(records);
								this.close();
							}.bind(this)
					 }];
		return result;				
	},
	rowdblclick: function(event){
		var records = this.grid.getSelectionModel().getSelections();
		this.callback(records);
		this.close();
	}
	
})